package com.uniledger.exchange.login;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;
import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.uniledger.exchange.wallet.WalletKey;

/**
 * 用户管理类
 */
@Entity(tableName = "uni_admin")
public class Admin implements Parcelable {

    @PrimaryKey(autoGenerate = true)
    public long id;
    public long uid;
    public boolean isSignIn;//是否登录
    public boolean isLockPin;//是否设置锁屏密码
    public String pin;//锁屏密码
    @SerializedName("name")
    public String firstName;
    public String lastName;
    public String mobile;
    @SerializedName("logo")
    public String avatar;
    @SerializedName("access_token")
    public String token;
    @SerializedName("expired_at")
    public String expire;//token  过期时间

    @SerializedName("issue_addr")
    public String issuingAccountId;

    @SerializedName("base_addr")
    public String baseAccountId;

    /**
     * 0:未登录
     * 1:未创建
     * 2:已创建
     * 3:已备份
     */
    public int walletFlag;//是否已创建钱包公私钥

    @SerializedName("country_code")
    public String countryCode;//国家码

    public String countryLocale;//简写
    public String countryEN;//英文
    public String countryZH;//中文

    @Ignore
    public WalletKey walletKey;

    @Ignore
    public Admin(long uid) {
        this.uid = uid;
        this.isSignIn = true;
        this.isLockPin = true;
    }

    @Ignore
    public Admin(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public Admin(long uid, boolean isSignIn, String firstName, String lastName, String mobile) {
        this.uid = uid;
        this.isSignIn = isSignIn;
        this.firstName = firstName;
        this.lastName = lastName;
        this.mobile = mobile;
    }

    @Ignore
    public Admin() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeLong(this.uid);
        dest.writeByte(this.isSignIn ? (byte) 1 : (byte) 0);
        dest.writeByte(this.isLockPin ? (byte) 1 : (byte) 0);
        dest.writeString(this.pin);
        dest.writeString(this.firstName);
        dest.writeString(this.lastName);
        dest.writeString(this.mobile);
        dest.writeString(this.avatar);
        dest.writeString(this.token);
        dest.writeString(this.expire);
        dest.writeString(this.issuingAccountId);
        dest.writeString(this.baseAccountId);
        dest.writeInt(this.walletFlag);
        dest.writeString(this.countryCode);
        dest.writeString(this.countryLocale);
        dest.writeString(this.countryEN);
        dest.writeString(this.countryZH);
        dest.writeParcelable(this.walletKey, flags);
    }

    protected Admin(Parcel in) {
        this.id = in.readLong();
        this.uid = in.readLong();
        this.isSignIn = in.readByte() != 0;
        this.isLockPin = in.readByte() != 0;
        this.pin = in.readString();
        this.firstName = in.readString();
        this.lastName = in.readString();
        this.mobile = in.readString();
        this.avatar = in.readString();
        this.token = in.readString();
        this.expire = in.readString();
        this.issuingAccountId = in.readString();
        this.baseAccountId = in.readString();
        this.walletFlag = in.readInt();
        this.countryCode = in.readString();
        this.countryLocale = in.readString();
        this.countryEN = in.readString();
        this.countryZH = in.readString();
        this.walletKey = in.readParcelable(WalletKey.class.getClassLoader());
    }

    public static final Creator<Admin> CREATOR = new Creator<Admin>() {
        @Override
        public Admin createFromParcel(Parcel source) {
            return new Admin(source);
        }

        @Override
        public Admin[] newArray(int size) {
            return new Admin[size];
        }
    };
}
